<?php
/**
 * @author 	 	 supfire@sohu.com
 * @copyright    	 sns
 * @version      	 1.0
 * @name 		 act.php
 * @todo 		 动一下 action
 * @final 		 2009-05-25
 */
define('IN_YCTOOL', true);//定义该文件合法性
require_once('config.php');
require_once(DIR_COMM . 'common.php');
$menu = 1;//导航为普通用户。
$userpathpre = './';
$user->isLogin($userpathpre);

$userid = $user->userinfo['userid'];
$uid	= isset($_GET['uid']) ? $_GET['uid'] : 0;
$action	= isset($_GET['action']) ? $_GET['action'] : '';
$userpathusr	= 'userdata/'.Func::getFilePath($userid);
$userpathact	= $userpathusr . 'act/';
$userpath	= $userpathpre . $userpathact;
$actionPost	= isset($_POST['actionPost']) ? $_POST['actionPost'] : "";

//处理操作
require_once DIR_COMM.'template.func.php';
switch ($action)
{
case 'add':

    if($actionPost)
    {
	if(!file_exists($userpath))
	{
	    @mkdir($userpath);
	}
	$newfile = time();
	$file = &$_FILES["file"];
	if ($file["size"])
	{
	    if ($file["error"] == 1 || $file["error"] == 2)
	    {
		$error .= "图片“" . $file["name"] . "”太大了，不能超过2M";
	    }
	    else if ($file["error"] == 3 || $file["error"] == 4)
	    {
		$error .= "图片“" . $file["name"] . "”上传错误，请重新上传";
	    }
	    else if ($file["size"] > 2000000)
	    {
		$error .= "图片“" . $file["name"] . "”太大了，不能超过2M";
	    }
	    else if (!in_array($file["type"], array("image/gif", "image/jpeg", "image/pjpeg", "image/png", "image/x-png")))
	    {
		$error .= "您上传的文件“" . $file["name"] . "”不属于GIF、JPG、PNG中的任何一种";
	    }
	    if ($error)
	    {
		$text = $error;
		require_once(DIR_VIEWS . 'plugins/act/addact.php');
		exit;
	    }
	    func::imageIsResize($file["tmp_name"], 20, 20, $userpath . $newfile . '0.jpg');
	    @move_uploaded_file($file["tmp_name"], $userpath . $newfile . '.jpg');
	}
	unset($file);
	//处理图片数据
    	$act1		= isset($_POST['act1']) ? $_POST['act1'] : '';
	$act2		= isset($_POST['act2']) ? $_POST['act2'] : '';
	$act1		= func::trChar($act1);
	$act2		= func::trChar($act2);
	
	//@include_once($userpathpre.$userpathusr.'config/money.php');
	//if($variablemoney[$userid]["money"] >= 200)
	//{
	    //$variablemoney[$userid]["money"] = $variablemoney[$userid]["money"] - 200;
	    //func::operateFile('variablemoney', $variablemoney, $userpathpre.$userpathusr.'config/money', 'php', 2);   
	    act::addAct($act1, $act2, $newfile, $userpath);//添加动 。
	    $text = '已经添加成功，单击 <a href="javascript:history.back()">这里继续添加动作</a> ；
		<a href="act.php">或者发送动作</a> ';
	//}
	//else
	//{
	//    $text = '您的现金不足，单击 <a href="../../user.php?action=send">这里邀请朋友赚取现金</a> ；
	//		<a href="act.php">或者发送动作</a> ';	
	//}
    }




    break; 
case 'modify':

    $newfile	= isset($_GET['actid']) ? $_GET['actid'] : 0;
    @include_once($userpath . 'act.php');
    if($actionPost == 'add')
    {
	$file = &$_FILES["file"];
	if ($file["size"])
	{
	    if ($file["error"] == 1 || $file["error"] == 2)
	    {
		$error .= "图片“" . $file["name"] . "”太大了，不能超过2M";
	    }
	    else if ($file["error"] == 3 || $file["error"] == 4)
	    {
		$error .= "图片“" . $file["name"] . "”上传错误，请重新上传";
	    }
	    else if ($file["size"] > 2000000)
	    {
		$error .= "图片“" . $file["name"] . "”太大了，不能超过2M";
	    }
	    else if (!in_array($file["type"], array("image/gif", "image/jpeg", "image/pjpeg", "image/png", "image/x-png")))
	    {
		$error .= "您上传的文件“" . $file["name"] . "”不属于GIF、JPG、PNG中的任何一种";
	    }
	    if ($error)
	    {
		$text = $error;
		require_once(DIR_VIEWS . 'plugins/act/modify.php');
		exit;
	    }
	    func::imageIsResize($file["tmp_name"], 20, 20, $userpath . $newfile . '0.jpg');
	    @move_uploaded_file($file["tmp_name"], $userpath . $newfile . '.jpg');
	}

	unset($file);
	//处理图片数据
    	$act1		= isset($_POST['act1']) ? $_POST['act1'] : '';
	$act2		= isset($_POST['act2']) ? $_POST['act2'] : '';
	$act1		= func::trChar($act1);
	$act2		= func::trChar($act2);
	act::updateAct($act1, $act2, $newfile, $userpath);
	$text = '
		已经修改，单击 <a href="act.php?action=modify&actid='.$actid.'">这里返回修改页面</a> ；
		<div id="messagebox_close" type=button value="Close" onclick="self.parent.tb_remove(1);"><img src="image/default/img_close.gif" />&nbsp;<a href="#">关闭</a></div>
	       	';
    }
    $variableact = $variableact[$newfile];
    $variableact = func::stripslashesArray($variableact);


    break; 
case 'set':

    if($actionPost)
    {
	$actionid	= isset($_POST['actionid']) ? $_POST['actionid'] : 0;
  
	if(!$actionid)
	{
	    $text = '请在下面选择所要添加到首页的动作';
	}
	if($actionid)
	{
	    if(count($actionid) > 3)
	    {
		$text = '选择过多，最多3个';	
	    }
	    else
	    {
		if(act::setAct($actionid, $userid, $userpathpre . $userpathusr . 'config/'))
		{
		    $text = '已经设置成功';
		}
	    }
	}
    }
 
    @include_once($userpath.'act.php');
    //删除处理
    $actiondel	= isset($_GET['actiondel']) ? $_GET['actiondel'] : '';
    if($actiondel == 'delact') //目前只有单条删除
    {
	$actid	= isset($_GET['actid']) ? $_GET['actid'] : 0;
	if($variableact[$actid])
	{
	    act::deleteActOne($userpath, $actid);
	    @unlink($userpath.$newfile.'.jpg');
	    @unlink($userpath.$newfile.'0.jpg');
	
	   // @include_once($userpathpre.$userpathusr.'config/money.php');
	   // $variablemoney[$userid]["money"] = $variablemoney[$userid]["money"] + 100;
	   // func::operateFile('variablemoney', $variablemoney, $userpathpre.$userpathusr.'config/money', 'php', 2);   

	    //$text = '动作删除成功您的金钱增加 100 金 目前为：'.$variablemoney[$userid]["money"].' 金';
	    unset($actid);
	    unset($actiondel);
	}
	else
	{
	    $text = '动作不存在，如果有问题可以联系管理员 <a href="other/impeach.php?keepThis=true&TB_iframe=true&height=290&width=360" title="给我们提意见" class="thickbox">给我们提意见</a>'; 
	}
    }   
    @include_once($userpathpre . $userpathusr . 'config/setact.php');
    $variablesetact = unserialize($variablesetact[$userid]['actionid']);


    break; 
default:;

    if($actionPost)
    {
	$privacy	= isset($_POST['privacy']) ? $_POST['privacy'] : 0;
    	$actionid	= isset($_POST['actionid']) ? $_POST['actionid'] : 0;
	$touid		= isset($_POST['userid']) ? $_POST['userid'] : 0;

	if(!$actionid)
	{
	    $textAct = '请您在下面选择要发送的动作';
	}
	if($touid)
	{
	    if(count($touid) > 20)
	    {
		$textUser = '选择好友过多，最多20个';	
	    }
	    else
	    {
		require_once(DIR_CTRL . 'msg.class.php');
		require_once(DIR_CTRL . 'msg.func.php');
		if(act::sendAct($actionid, $touid, $userid, $privacy))
		{
		    $text = '您的动作已经发送出去，好友登录时，会看到这个动作。';
		}	    
	    }
	}
	else
	{
	    $textUser = '请您选择好友';
	}
    }
    //读取好友数组 
    $arr_all_friend = array();
    @include_once($userpathpre.$userpathusr.'myfriend.php');
    @include_once($userpath.'act.php');
}

require_once tpl('act'.$action.'.html', $tpldir);
exit;
?>
